import QtQuick 2.0
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.0
import "storage.js" as Storage

Item {
    id:root
    width: 850
    height: 580
    property real minSize:  Math.min(width/850, height/580)

    function writeRegSingalLim(handle, sqlName){
        Storage.writeRegSingalLimit(handle.valueText, sqlName)
    }

    function refurbishA()
    {
        text_aug.valueText = Storage.readRegSingalLimit("A套机端电压系数")
        text_aig.valueText = Storage.readRegSingalLimit("A套机端电流系数")
        text_aus.valueText = Storage.readRegSingalLimit("A套系统电压系数")
        text_ail.valueText = Storage.readRegSingalLimit("A套励磁电流系数")
        text_atb.valueText = Storage.readRegSingalLimit("A套同步电压系数")
        text_apq.valueText = Storage.readRegSingalLimit("A套有功功率系数")
    }
    function refurbishB()
    {
        text_bug.valueText = Storage.readRegSingalLimit("B套机端电压系数")
        text_big.valueText = Storage.readRegSingalLimit("B套机端电流系数")
        text_bus.valueText = Storage.readRegSingalLimit("B套系统电压系数")
        text_bil.valueText = Storage.readRegSingalLimit("B套励磁电流系数")
        text_btb.valueText = Storage.readRegSingalLimit("B套同步电压系数")
        text_bpq.valueText = Storage.readRegSingalLimit("B套有功功率系数")
    }

    Timer{
        interval: 2000
        repeat: false
        triggeredOnStart: false
        running: true
        onTriggered: {
            text_aug.tipText = Storage.readRegScope("A套机端电压系数")
            text_aig.tipText = Storage.readRegScope("A套机端电流系数")
            text_aus.tipText = Storage.readRegScope("A套系统电压系数")
            text_ail.tipText = Storage.readRegScope("A套励磁电流系数")
            text_atb.tipText = Storage.readRegScope("A套同步电压系数")
            text_apq.tipText = Storage.readRegScope("A套有功功率系数")
            text_bug.tipText = Storage.readRegScope("B套机端电压系数")
            text_big.tipText = Storage.readRegScope("B套机端电流系数")
            text_bus.tipText = Storage.readRegScope("B套系统电压系数")
            text_bil.tipText = Storage.readRegScope("B套励磁电流系数")
            text_btb.tipText = Storage.readRegScope("B套同步电压系数")
            text_bpq.tipText = Storage.readRegScope("B套有功功率系数")
        }
    }

    onFocusChanged:{
        if(!focus) return
        refurbishA()
        refurbishB()
    }

    SwipeView
    {
        id: sv_this
        width:parent.width
        height: parent.height*0.85
        clip: true
        Component.onCompleted:{contentItem.highlightMoveDuration = 0}       //将移动时间设为0

        Item{
            Text {
                y: 20*root.minSize
                color: "#44fdfd"
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("A通道模拟量系数")
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 40*root.minSize
            }

            Rectangle {
                y: 100*root.minSize
                width: 400*root.minSize
                height: 380*root.minSize
                color: "#6692e8bc"
                radius: 10*root.minSize
                anchors.horizontalCenter: parent.horizontalCenter

                ColumnLayout {
                    property real textSize: 30*root.minSize
                    x: 10*root.minSize
                    width: 380*root.minSize
                    anchors.bottom: parent.bottom
                    anchors.top: parent.top

                    EXC_Normal_DoubleTextSytle3{
                        id: text_aug
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("机端电压系数Kug:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_aig
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("机端电流系数Kig:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_aus
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("励磁电流系数Kus:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_ail
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("励磁电流系数Kil:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_atb
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("同步电压系数Ktb:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_apq
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("有功功率系数Kpq:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: btn_ASave
                nameFontpixelSize: 25*root.minSize
                y: 410*root.minSize
                width: 140*root.minSize
                height: 50*root.minSize
                anchors.rightMargin: 10
                anchors.right: parent.right
                nameText: qsTr("保存参数")
                onClicked: {
                    writeRegSingalLim(text_aug, "A套机端电压系数")
                    writeRegSingalLim(text_aig, "A套机端电流系数")
                    writeRegSingalLim(text_aus, "A套系统电压系数")
                    writeRegSingalLim(text_ail, "A套励磁电流系数")
                    writeRegSingalLim(text_atb, "A套同步电压系数")
                    writeRegSingalLim(text_apq, "A套有功功率系数")
                    timerA_ass.start()
                }

                Timer{
                    id:timerA_ass
                    interval: 700
                    repeat: true
                    triggeredOnStart: false
                    property int thisCounter: 0
                    onTriggered: {
                        if(thisCounter>0)
                            refurbishA()
                        thisCounter++
                        if(thisCounter>3) {
                            thisCounter=0
                            stop()
                        }
                    }
                }
            }

            onFocusChanged:{
                if(!focus) return
                refurbishA()
            }
        }

        Item{
            Text {
                x: 220*root.minSize
                y: 20*root.minSize
                color: "#44fdfd"
                text: qsTr("B通道模拟量系数")
                anchors.horizontalCenter: parent.horizontalCenter
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                font.pixelSize: 40*root.minSize
            }
            Rectangle {
                x: 220*root.minSize
                y: 100*root.minSize
                width: 400*root.minSize
                height: 380*root.minSize
                color: "#6692e8bc"
                radius: 10*root.minSize
                anchors.horizontalCenter: parent.horizontalCenter
                property real textSize: 30*root.minSize

                ColumnLayout {
                    x: 10*root.minSize
                    width: 380*root.minSize
                    anchors.bottom: parent.bottom
                    anchors.top: parent.top
                    property real textSize: 30*root.minSize

                    EXC_Normal_DoubleTextSytle3{
                        id: text_bug
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("机端电压系数Kug:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_big
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("机端电流系数Kig:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_bus
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("励磁电流系数Kus:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_bil
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("励磁电流系数Kil:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_btb
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("同步电压系数Ktb:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                    EXC_Normal_DoubleTextSytle3{
                        id: text_bpq
                        width: parent.width
                        Layout.preferredHeight: 40*root.minSize
                        Layout.fillWidth: true
                        funcText: qsTr("有功功率系数Kpq:")
                        valueText: "???"
                        textSize:parent.textSize
                    }
                }

            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: btn_BSave
                nameFontpixelSize: 25*root.minSize
                x: 670*root.minSize
                y: 410*root.minSize
                width: 140*root.minSize
                height: 50*root.minSize
                anchors.rightMargin: 10
                anchors.right: parent.right
                nameText: qsTr("保存参数")
                onClicked: {
                    writeRegSingalLim(text_bug, "B套机端电压系数")
                    writeRegSingalLim(text_big, "B套机端电流系数")
                    writeRegSingalLim(text_bus, "B套系统电压系数")
                    writeRegSingalLim(text_bil, "B套励磁电流系数")
                    writeRegSingalLim(text_btb, "B套同步电压系数")
                    writeRegSingalLim(text_bpq, "B套有功功率系数")
                    timerB_ass.start()
                }

                Timer{
                    id:timerB_ass
                    interval: 1000
                    repeat: true
                    triggeredOnStart: false
                    property int thisCounter: 0
                    onTriggered: {
                        if(thisCounter>0)
                            refurbishB()
                        thisCounter++
                        if(thisCounter>3) {
                            thisCounter=0
                            stop()
                        }
                    }
                }
            }

            onFocusChanged:{
                if(!focus) return
                refurbishB()
            }
        }
        onCurrentIndexChanged: {
            if(sv_this.currentIndex==0) {button.checked=true;button2.checked=false}
            if(sv_this.currentIndex==1) {button2.checked=true;button.checked=false}
        }

    }

    EXC_Normal_BtnSytle {
        id: button
        nameText: qsTr("A通道")
        width: parent.width*0.15
        height: parent.height*0.09
        checked: true
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.1
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            if(sv_this.currentIndex==0) checked = true;
            else sv_this.currentIndex = 0
        }
    }

    EXC_Normal_BtnSytle {
        id: button2
        nameText: qsTr("B通道")
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.43
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            if(sv_this.currentIndex==1) checked = true;
            else sv_this.currentIndex = 1
        }
    }

    EXC_Normal_BtnUncheckStyle {
        id: button3
        nameText: qsTr("返回")
        nameFontpixelSize: 30*Math.min(root.width/850, root.height/580)
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.75
        anchors.topMargin: parent.height/32
        anchors.top: sv_this.bottom
        onClicked: {
            sw.currentIndex = 0
        }
    }
}

/*##^##
Designer {
    D{i:5;anchors_width:400;anchors_x:0}D{i:4;anchors_height:100;anchors_y:0}
}
##^##*/
